//
//  HTLeftMenuCell.m
//  HT_aigongzuo
//
//  Created by 周昭 on 16/9/1.
//  Copyright © 2016年 HT_Technology. All rights reserved.
//

#import "HTLeftMenuCell.h"
#import "HTMenuUserModel.h"

@interface HTLeftMenuCell()
@property (nonatomic, weak) UITableView *tableView;

/**
 *  箭头(这里为什么用stong不能让创建完了就被销毁)
 */
@property (nonatomic, strong) UIImageView *arrowView;
@end

@implementation HTLeftMenuCell

/**
 *  右边的控件
 */
- (UIImageView *)arrowView
{
    if (_arrowView == nil) {
        _arrowView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"common_icon_arrow"]];
    }
    return _arrowView;
}

/**
 *  创建自定义的cell
 */
+ (instancetype)cellWithTableView:(UITableView *)tableView
{
    static NSString *ID = @"menuCell";
    HTLeftMenuCell *cell  = [tableView dequeueReusableCellWithIdentifier:ID];
    
    if (cell == nil) {
        cell = [[HTLeftMenuCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:ID];
        cell.tableView = tableView;
        cell.selectedBackgroundView = [[UIView alloc] initWithFrame:cell.frame];
        cell.selectedBackgroundView.backgroundColor = [UIColor lightGrayColor];
    }
    return cell;
}

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    
    if (self) {
        // 标题
        self.textLabel.backgroundColor = [UIColor clearColor];
        self.textLabel.textColor = [UIColor blackColor];
        self.textLabel.highlightedTextColor = self.textLabel.textColor;
        self.textLabel.font = [UIFont systemFontOfSize:15];
        
        // 最右边的详情文字
        self.detailTextLabel.backgroundColor = [UIColor clearColor];
        self.detailTextLabel.textColor = [UIColor lightGrayColor];
        self.detailTextLabel.highlightedTextColor = self.detailTextLabel.textColor;
        self.detailTextLabel.font = [UIFont systemFontOfSize:13];
        
        self.backgroundColor = [UIColor clearColor];
    }
    return self;
}

/**
 *  重写setter方法拿到模型
 */
- (void)setModel:(HTMenuUserModel *)model
{
    _model = model;
    
    // 1.设置数据
    [self setUpData];
    
    // 2.设置右边的控件
//    [self setUpRightView];
}

/**
 *  设置数据
 */
- (void)setUpData
{
    if (self.model.isWebIcon) {
        [self.imageView sd_setImageWithURL:[NSURL URLWithString:self.model.icon] placeholderImage:[UIImage imageNamed:@"more"]];
    } else {
        [self.imageView setImage:[UIImage imageNamed:self.model.icon]];
        [self.imageView setHighlightedImage:[UIImage imageNamed:[NSString stringWithFormat:@"%@h",self.model.icon]]];
    }
    self.textLabel.text = self.model.title;
}

/**
 *  设置右边的控件
 */
- (void)setUpRightView
{
    self.accessoryView = self.arrowView;
}

/**
 *  这里写右边的控件类型
 */
- (void)setIndexPath:(NSIndexPath *)indexPath
{
    _indexPath = indexPath;
}
@end
